package com.monitor.controller.back;

import com.alibaba.fastjson.JSON;
import com.monitor.common.MonitorConstants;
import com.monitor.common.aes.AESOperator;
import com.monitor.controller.BaseController;
import com.monitor.pojo.SysUser;
import com.monitor.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SettingController
 * @Package com.kele.controller
 * @Description TODO
 * @Author zhixingbai
 * @Create 2018/9/3013:42
 */
@RestController
@RequestMapping("/back/setting")
public class SettingController extends BaseController {

    @Autowired
    private SettingService settingService;

    @RequestMapping("/info")
    public Object setting() {
        logger.info("访问系统设置");
        SysUser sysUser = (SysUser) getSessionAttr(MonitorConstants.USER_SESSION_KEY);
        sysUser.setPassword(AESOperator.getInstance().decrypt(sysUser.getPassword()));
        return sysUser;
    }

    @RequestMapping("/edit")
    public Object edit(SysUser sysUser) {
        logger.info("系统设置:{}", JSON.toJSONString(sysUser));
        sysUser.setPassword(AESOperator.getInstance().encrypt(sysUser.getPassword()));
        return settingService.setting(sysUser);
    }
}
